  $(function(){
    $("#tree").dynatree({
      title: "Event samples",
//      checkbox: true,
//      persist: true,
      onQueryActivate: function(activate, node) {
        logMsg("onQueryActivate(%o, %o)", activate, node);
//        return false;
      },
      onActivate: function(node) {
        logMsg("onActivate(%o)", node);
        $("#echoActive").text(node.data.href);
        if( node.data.href )
          window.open(node.data.href);
      },
      onDeactivate: function(node) {
        logMsg("onDeactivate(%o)", node);
        $("#echoActive").text("-");
      },

      onQuerySelect: function(select, node) {
        logMsg("onQuerySelect(%o, %o)", select, node);
        if( node.data.isFolder )
          return false;
      },
      onSelect: function(select, node) {
        logMsg("onSelect(%o, %o)", node);
        var s = node.tree.getSelectedNodes().join(", ");
        $("#echoSelected").text(s);
      },

      onQueryExpand: function(expand, node) {
        logMsg("onQueryExpand(%o, %o)", expand, node);
//        return false;
      },
      onExpand: function(expand, node) {
        logMsg("onExpand(%o, %o)", expand, node);
      },

      onLazyRead: function(node) {
        logMsg("onLazyRead(%o)", node);
      },

      onFocus: function(node) {
        logMsg("onFocus(%o)", node);
        $("#echoFocused").text(node.data.href);
        // Auto-activate focused node after 2 seconds
        node.scheduleAction("activate", 2000);
      },
      onBlur: function(node) {
        logMsg("onBlur(%o)", node);
        $("#echoFocused").text("-");
      },

      onClick: function(node, event) {
        logMsg("onClick(%o, %o)", node, event);
        if( event.shiftKey && node.isLazy )
          alert("ctrl");
        //return false;
      },
      onDblClick: function(node, event) {
        logMsg("onDblClick(%o, %o)", node, event);
        node.toggleSelect();
      },
      onKeydown: function(node, event) {
        logMsg("onKeydown(%o, %o)", node, event);
        switch( event.which ) {
        case 32: // [space]
          node.toggleSelect();
          return false;
        }
      },
      onKeypress: function(node, event) {
        logMsg("onKeypress(%o, %o)", node, event);
      }
    });

  });
